function refresh(function_name){
	var post_data = {
		p_id : $("select").val() || '2',
		c_id : $("#cid li[data-selected='1']").val() || '0',
        f_id : $("#fid li[data-selected='1']").val() || '0',
        s_id : $("#sid li[data-selected='1']").val() || '0',
        d_level : $("#d_lev li[data-selected='1']").val() || '0',
        a_id : $("#aid li[data-selected='1']").val() || '0'
	};

	$.ajax({
		url : '/doctor',
		data : post_data,
		dataType : 'json',
		type : 'post',
		success : function_name
	})
};






function select_change(res) {
    var c_html = "";
    $.each(res.city, function(idx, obj) {
        if(idx == 0)
            c_html += "<li data-selected=\"1\" value="+obj.area_id +"\" class=\"select-cur\">"+obj.area_name+"</li>";
        else
            c_html += "<li value="+obj.area_id+"\">"+obj.area_name+"</li>";
    });
    $("#cid ul").html(c_html);

    var a_html = "<li data-selected=\"1\" value= \"0\" class=\"select-cur\">全部</li>";
    $.each(res.area, function(idx, obj) {
            a_html += "<li value="+obj.area_id+"\">"+obj.area_name+"</li>";
    });
	$("#aid ul").html(a_html);

    refresh_doc_list(res);

}

function cid_click(res) {
    var a_html = "<li data-selected=\"1\" value= \"0\" class=\"select-cur\">全部</li>";
    $.each(res.area, function(idx, obj) {
        a_html += "<li value="+obj.area_id+"\">"+obj.area_name+"</li>";
    });
    $("#aid ul").html(a_html);
    refresh_doc_list(res);
}

function fid_click(res) {
    var s_html = "<li data-selected=\"1\" value= \"0\" class=\"select-cur\">全部</li>";
    $.each(res.dept_s, function(idx, obj) {
        s_html += "<li value="+obj.id+"\">"+obj.name+"</li>";
    });
    $("#sid ul").html(s_html);
    refresh_doc_list(res);
}

function refresh_doc_list(res) {
    var pre = document.getElementById("doctor_list");
    pre.parentNode.removeChild(pre);

    var newiframe = document.createElement('iframe'); //动态创建框架
    newiframe.id = "doctor_list";
    newiframe.scrolling="no";
    newiframe.width="95%";
    newiframe.height="500px";
    newiframe.src=res.doc_list_url;            //框架中加载的页面
    var dest =  document.getElementById("doctor_list_iframe");
    dest.appendChild(newiframe);
}


$(document).ready(function(){
	$("select").change(function(){
		refresh(select_change);
	});
    $("#cid").on('click','li',function(){
        refresh(cid_click);
    });
    $("#fid").on('click','li',function(){
        refresh(fid_click);
    });
    $("#sid").on('click','li',function(){
        refresh(refresh_doc_list);
    });
    $("#d_lev").on('click','li',function(){
        refresh(refresh_doc_list);
    });
    $("#aid").on('click','li',function(){
        refresh(refresh_doc_list);
    });
});